SoSe2021
t.test()t.test(x, y = NULL,
alternative = c("two.sided", "less", "greater"),
mu = 0, paired = FALSE, var.equal = FALSE,
conf.level = 0.95, ...)\[t=\frac{\bar{X}-\mu_0}{s_{\bar{X}}}=\frac{\bar{X}-\mu_0}{\frac{s}{\sqrt{n}}}\Rightarrow~~\text{wenn}~\mu_0 = 0: \frac{\bar{X}}{\frac{s}{\sqrt{n}}}\]
Unterscheidet sich unsere Stichprobe zum Zugverhalten des Buchfinks (BF1) von einer anderen Stichprobe (BF2), für die wir nur den Mittelwert kennen?
| Kenngröße | BF1 | BF2 |
|---|---|---|
| Mittelwert | 1800km | 1697km |
| Standardabweichung s | ±900km | ? |
| Stichprobengröße n | 20 | ? |
Unterscheidet sich unsere Stichprobe zum Zugverhalten des Buchfinks (BF1) von einer anderen Stichprobe (BF2), für die wir nur den Mittelwert kennen?
| Kenngröße | BF1 | BF2 |
|---|---|---|
| Mittelwert | 1800km | 1697km |
| Standardabweichung s | ±900km | ? |
| Stichprobengröße n | 20 | ? |
| Kennwert: | \(\mu\) bzw. \(\bar{X}\) |
| H0: | \(BF1 = BF2\) |
| HA: | \(BF1 \neq BF2\) |
| Voraussetzung: | Erfüllt (Stichprobe ist normal verteilt) |
| Teststatistik: | t |
| alpha: | 0.05 |
| FG: | n-1 = 19 |
| p-Wert: | Der t-Wert wird mit dem \(t_{krit}\) aus der t-Verteilung verglichen. |
bf
[1] 697.62 1619.21 742.97 1065.16 1177.78 26.50 2764.10 2021.90 621.37
[10] 3215.24
[ reached getOption("max.print") -- omitted 10 entries ]# Berechnung des t-Werts (t.val <- (mean(bf)-1697)/(sd(bf)/sqrt(20)) )
[1] 0.5118085
# Kritischer t-Wert qt(p = c(0.025, 0.975), df = 19)
[1] -2.093024 2.093024
# P für berechneten t-Wert pt(t.val, df = 19, lower.tail = FALSE)*2
[1] 0.6146824
t.test(x = bf, mu = 1697, alternative = "two.sided") # default
One Sample t-test
data: bf
t = 0.51181, df = 19, p-value = 0.6147
alternative hypothesis: true mean is not equal to 1697
95 percent confidence interval:
1378.786 2221.213
sample estimates:
mean of x
1799.999 → Es gibt keinen signifikanten Unterschied zwischen unserer Stichprobe und der Vergleichsstichprobe (t = 0.51, df = 19, p > 0.5).
\[t=\frac{(\bar{X}_1-\bar{X}_2) -(\mu_1 - \mu_2)}{s_p \sqrt{\frac{1}{n_1} + \frac{1}{n_2}}} \Rightarrow~~\text{wenn}~~\mu_1-\mu_2=0:~t = \frac{(\bar{X}_1-\bar{X}_2)}{s_p \sqrt{\frac{1}{n_1} + \frac{1}{n_2}}}\]
\(s_p\) = Standardabweichung der gepoolten Stichprobe: \(s_p = \sqrt{\frac{(n_1-1)s_1^2 + (n_2 -1)s_2^2}{(n_1-1) + (n_2-1)}}\)
\[t=\frac{(\bar{X}_1-\bar{X}_2) -(\mu_1 - \mu_2)}{\sqrt{\frac{s_1^2}{n_1} + \frac{s_2^2}{n_2}}}\]
= “Welch Two Sample t-test” (Standardeinstellung in R)
\[t = \frac{\bar{d}-\mu_d}{s_{\bar{d}}} = \frac{\bar{d}-\mu_d}{\frac{s}{\sqrt{n}}}\]
mit \(FG = n-1\)
t.test()t.test(x, mu)t.test(
x,
y, var.equal = TRUE)t.test(
x,
y, var.equal = TRUE, alternative = “greater”)t.test(
x,
y, alternative = “smaller”)t.test(
x,
y, paired = TRUE, var.equal = TRUE)t.test(
x,
y, paired = TRUE, alternative = “greater”)Unterscheidet sich das durchschnittliche Zugverhalten zwischen Buchfinken und Mönchsgrasmücken?
| Kenngröße | Buchfink | Mönchsgrasmücke |
|---|---|---|
| Mittelwert | 1800km | 3000km |
| Standardabweichung s | ±900km | ±1000km |
| Stichprobengröße n | 20 | 30 |
| Kennwert: | \(\mu\) bzw. \(\bar{X}\) |
| H0: | \(\mu_{BF} = \mu_{MGM}\) |
| HA: | \(\mu_{BF} \neq \mu_{MGM}\) |
| Voraussetzung: | Erfüllt (Stichproben sind normal verteilt und Varianzen gleich) |
| Teststatistik: | \(t = \frac{(\bar{X}_{BF}-\bar{X}_{MGM})}{s_p \sqrt{\frac{1}{n_{BF}} + \frac{1}{n_{MGM}}}}\) |
| alpha: | 0.05 |
| FG: | \((n_{BF}-1)+(n_{MGM}-1)\) = 19 + 29 |
| p-Wert: | Der t-Wert wird mit dem \(t_{krit}\) aus der t-Verteilung verglichen. |
t.test(x = bf, y = mgm, var.equal = TRUE)
Two Sample t-test
data: bf and mgm
t = -4.3226, df = 48, p-value = 7.733e-05
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-1758.1677 -641.8326
sample estimates:
mean of x mean of y
1799.999 3000.000 irisirisset <- iris$Sepal.Length[iris$Species=="setosa"] vir <- iris$Sepal.Length[iris$Species=="virginica"]
irist.test(x = set, y = vir, alternative = 'less')
Welch Two Sample t-test
data: set and vir
t = -15.386, df = 76.516, p-value < 2.2e-16
alternative hypothesis: true difference in means is less than 0
95 percent confidence interval:
-Inf -1.410804
sample estimates:
mean of x mean of y
5.006 6.588 Frage: Wie groß ist die Wahrscheinlichkeit, dass die beobachtete Rangsumme zufällig entstanden ist, wenn beide Stichproben zur gleichen Verteilung gehören?
pnorm(z, mean = 0, sd = 1) ermittelt werden.dwilcox(x, m, n)
pwilcox(x, m, n) qwilcox(c(0.025, 0.975), m, n)
…Great tits in cities sing faster and at a higher pitch compared to their conspecifics dwelling in forests, as reported in this issue by Slabbekoorn and den Boer-Visser [6]. They suggest that the birds changed their songs to make them stand out against the masking traffic noise in urban areas. ..
Vorgehensweise?
Fragestellung?
Prüfen auf Normalverteilung?
| Kennwert: | \(\mu_M\) bzw. \(\bar{X}_M\) |
| H0: | \(\mu_{M(Stadt)} \leq \mu_{M(Land)}\) bzw. \(\mu_{M(Stadt)} = \mu_{M(Land)}\) |
| HA: | \(\mu_{M(Stadt)}\) > \(\mu_{M(Land)}\) bzw. \(\mu_{M(Stadt)} \neq \mu_{M(Land)}\) |
| Voraussetzung: | Fällt weg |
| Teststatistik: | U |
| alpha: | 0.05 |
| FG: | n-1 = 19 |
| p-Wert: | Der U-Wert wird mit dem \(U_{krit}\) aus der Wilcoxon-Verteilung verglichen. |
| Messort | Lautstärke (in dB) | Rang |
|---|---|---|
| Stadt | 52 | 10 |
| Stadt | 44 | 6 |
| Stadt | 64 | 12 |
| Stadt | 53 | 11 |
| Stadt | 31 | 2 |
| Stadt | 50 | 9 |
| Land | 47 | 7 |
| Land | 29 | 1 |
| Land | 32 | 3 |
| Land | 42 | 5 |
| Land | 37 | 4 |
| Land | 48 | 8 |
\[U_x = m*n+\frac{m(m+1)}{2}-R_x\] \[U_y = m*n+\frac{n(n+1)}{2}-R_y\]
\(R_{Stadt}=50\)
\(R_{Land}=28\)
\(U_{Stadt}=6*6+\frac{6(6+1)}{2}-50 = 7\)
\(U_{Land}=6*6+\frac{6(6+1)}{2}-28 = 29\)
\(\Rightarrow U_{min} = U_{Stadt} = 7\)
# 2-seitig (HA: Stadt != Land) qwilcox(0.025, m = 6, n = 6)
[1] 6
pwilcox(7, m = 6, n = 6) * 2
[1] 0.09307359
# 1-seitig (HA: Stadt > Land) qwilcox(0.05, m = 6, n = 6)
[1] 8
pwilcox(7, m = 6, n = 6)
[1] 0.0465368
wilcox.test()wilcox.test() Funktion.wilcox.test(x = land, y = stadt)
Wilcoxon rank sum exact test
data: land and stadt
W = 7, p-value = 0.09307
alternative hypothesis: true location shift is not equal to 0H0: Die Verteilungen von x und y unterscheiden sich nicht in ihrem Lageparameter \(\mu\) ( H0: \(\mu_x - \mu_y=0\)).
y Argument zugewiesen wird:wilcox.test(x = land, y = stadt)
Wilcoxon rank sum exact test
data: land and stadt
W = 7, p-value = 0.09307
alternative hypothesis: true location shift is not equal to 0wilcox.test(x = stadt, y = land)
Wilcoxon rank sum exact test
data: stadt and land
W = 29, p-value = 0.09307
alternative hypothesis: true location shift is not equal to 0wilcox.test(x = land, y = stadt, alternative = "less")
Wilcoxon rank sum exact test
data: land and stadt
W = 7, p-value = 0.04654
alternative hypothesis: true location shift is less than 0wilcox.test(x = stadt, y = land, alternative = "greater")
Wilcoxon rank sum exact test
data: stadt and land
W = 29, p-value = 0.04654
alternative hypothesis: true location shift is greater than 0Unterscheiden sich mit Fadenwürmern infizierte und mit Interleucin-33 behandelte Mäuse von nicht behandelten Kontrollen in der Zahl adulter Fadenwürmer im Dünndarm?
wurm <- data.frame( interleucin = c(5,5,5,6,8,10,10,11, 120), kontrolle = c(14,17,18,20,22,24,25,26,23) )
wilcox.test(wurm$interleucin, wurm$kontrolle)
Wilcoxon rank sum test with continuity correction
data: wurm$interleucin and wurm$kontrolle
W = 9, p-value = 0.006061
alternative hypothesis: true location shift is not equal to 0→ \(H_0\) kann abgelehnt werden. Es gibt einen signifikanten Unterschied.
t.test(wurm$interleucin, wurm$kontrolle, var.equal = FALSE)
Welch Two Sample t-test
data: wurm$interleucin and wurm$kontrolle
t = -0.079381, df = 8.1841, p-value = 0.9386
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-29.93629 27.93629
sample estimates:
mean of x mean of y
20 21 → \(H_0\) kann nicht abgelehnt werden. Es gibt keinen signifikanten Unterschied.
wilcox.test(wurm$interleucin[-9], wurm$kontrolle[-9])
Wilcoxon rank sum test with continuity correction
data: wurm$interleucin[-9] and wurm$kontrolle[-9]
W = 0, p-value = 0.0008989
alternative hypothesis: true location shift is not equal to 0→ \(H_0\) kann weiterhin abgelehnt werden. Es gibt einen signifikanten Unterschied.
t.test(wurm$interleucin[-9], wurm$kontrolle[-9], var.equal = FALSE)
Welch Two Sample t-test
data: wurm$interleucin[-9] and wurm$kontrolle[-9]
t = -7.5714, df = 11.524, p-value = 8.361e-06
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-17.080474 -9.419526
sample estimates:
mean of x mean of y
7.50 20.75 → Jetzt kann \(H_0\) abgelehnt werden.
wilcox.test(), aber mit Argument paired=TRUEwilcox.test()wilcox.test(
x,
y)wilcox.test(
x,
y, alternative = “greater”)wilcox.test(
x,
y, paired = TRUE)wilcox.test(
x,
y, paired = TRUE, alternative = “less”)Bei weiteren Fragen: saskia.otto(at)uni-hamburg.de

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License except for the borrowed and mentioned with proper source: statements.
Image on title and end slide: Section of an infrared satellite image showing the Larsen C ice shelf on the Antarctic Peninsula - USGS/NASA Landsat: A Crack of Light in the Polar Dark, Landsat 8 - TIRS, June 17, 2017 (under CC0 license)